/*
 * @lc app=leetcode.cn id=507 lang=javascript
 *
 * [507] 完美数
 */

// @lc code=start
/**
 * @param {number} num
 * @return {boolean}
 */
var checkPerfectNumber = function(num) {
    let s=0
    let v=1
    while(v<=(num/3)){
        if(num%v==0){
            s=s+v
        }
        v++
    }
    if(num%2==0)s=s+num/2
    return s==num
};
// @lc code=end

var checkPerfectNumber = function(num) {
    let s=0
    let v=1
    while(v<=(num/2)){
        if(num%v==0){
            s=s+v
        }
        v++
    }
    return s==num
};